# -*- coding: utf-8 -*- 

###########################################################
#                                                         #
# shooter - shooter game                                  #
#                                                         #
# 2011 - Andreas Grätz                                    #
#                                                         #
# andreaszdw@googlemail.com                               #
#                                                         #
# stack.py                                                #
#                                                         #
###########################################################

class Stack:
	def __init__(self):
		print "Stack.__init__()"
		self.data = []
	
	# This method pushes a state onto the stack, making it the top and the method top()
	# will return this on the next call.
	def push(self, data_):
		self.data.append(data_)
		
	# This method removes the current state from the top of the stack. The state below it 
	# will automaticly be retured by the next call to the top() method.
	def pop(self):

		if len(self.data) == 0:
			return 0
		
		data = self.top()
		self.data.pop(-1)
		return data
		
	# returns the top state in the stack (the active one) 
	def top(self):
		if len(self.data) == 0:
			#print "Stack empty: handle exception here"
			return 0
		else: 
			return self.data[-1]
	
	def empty(self):
		if len(self.data) == 0:
			return True
		else:
			return False
	
	# Cleans up the stack.
	# TODO: This function needs to be able to look through the stack
	# and pick out states that are left behind or that have had their
	# ready flag changed by the current state.
	def cleanup(self):
		if self.ready():
			pass
	
	def __del__(self):
		pass
